/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import Entities.Director;
import Entities.Movie;

import java.util.Date;
import javax.persistence.*;
import java.util.List;

/**
 *
 * @author sebastian
 */
public class DirectorService {

    protected EntityManager em;

    public DirectorService(EntityManager em) {
        this.em = em;
    }

    public Director createDirector(Long ID, String name, String lastName, 
            String picture, Date birthday, String birthPlace,
            List<Movie> movieEntitys) {
        Director person = new Director(ID);
        person.setName(name);
        person.setLastName(lastName);
        person.setPicture(picture);
        person.setBirthDate(birthday);
        person.setBirthPlace(birthPlace);
        person.setMovieEntitys(movieEntitys);
        
        em.persist(person);
        
        return person;
    }
    
    
    public void updateDirector(Long ID, String name, String lastName, 
            String picture, Date birthday, String birthPlace,
            List<Movie> movieEntitys) {
        Director person = findDirector(ID);
        person.setName(name);
        person.setLastName(lastName);
        person.setPicture(picture);
        person.setBirthDate(birthday);
        person.setBirthPlace(birthPlace);
        person.setMovieEntitys(movieEntitys);
        
        em.persist(person);
    }   
        
    public void removeDirector(Long ID) {
        Director person = findDirector(ID);
        if (person != null) {
            em.remove(person);
        }
    }

    public Director findDirector(Long ID) {
        return em.find(Director.class, ID);
    }

  
}

